﻿Public Class frmLogin
    '
    ' Formulaire d'identification de l'utilisateur
    '
    Private szSQL As String
    Private rs As ADODB.Recordset

    Private Sub frmLogin_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' raz code user
        gUserCode = "___"
        Me.Text = My.Application.Info.Title & " - " & My.Application.Info.Version.ToString
    End Sub

    Private Sub BO_ANNULER_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BO_ANNULER.Click
        ' Quitter la fenetre
        Me.Close()
    End Sub

    Private Sub BO_OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BO_OK.Click

        If TE_CD_UTI.Text = "" Or TE_PSW.Text = "" Then
            MsgBox("Veuillez saisir votre code utilisateur et votre mot de passe", MsgBoxStyle.Critical)
            TE_CD_UTI.Focus()
            Exit Sub
        End If

        ' Lire le mot de passe de l'utilisateur
        GetRecordset(ctDSN_AEM, "SELECT * FROM P_USERS WHERE CD_UTI = '" & TE_CD_UTI.Text & "'", rs)
        If rs.RecordCount <= 0 Then
            MsgBox("Utilisateur ou mot de passe incorrect !", MsgBoxStyle.Critical)
            Exit Sub
        Else
            If TE_PSW.Text <> rs.Fields("PSW").Value Then
                MsgBox("Utilisateur ou mot de passe incorrect !", MsgBoxStyle.Critical)
                rs.Close()
                TE_CD_UTI.Focus()
                Exit Sub
            End If
            ' Mémoriser les propriétés de l'utilisateur
            gUserCode = TE_CD_UTI.Text
            gUserNom = rs.Fields("NOM").Value
            gUserAcces = (rs.Fields("SECU").Value)
            rs.Close()
        End If
        ' fermer le form
        Me.Close()

    End Sub

End Class
